home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / lisp / eulisp / feel0_89.lha / Feel / Libs / CSP / driver.em < prev    next >
Encoding:
Text File  |  1993-07-18  |  2.9 KB  |  134 lines

  1. ;;; Xlisp code to drive an X window
  2.  
  3. (defmodule driver
  4.  
  5.   (lists
  6.    list-operators
  7.    extras0
  8.    macros0
  9.    streams    
  10.    semaphores
  11.    plists) ()
  12.   
  13. ;;  ( lists list-operators extras0 macros0 streams semaphores plists)
  14.   ()
  15.   (deflocal lock (make-semaphore))
  16.  
  17.   (put 'x-service 'plot 0)
  18.   (put 'x-service 'unplot 1)
  19.   (put 'x-service 'read-pixmap 2)
  20.   (put 'x-service 'clearwin 3)
  21.   (put 'x-service 'redraw 4)
  22.   (put 'x-service 'manage 5)
  23.   (put 'x-service 'move 6)
  24.   (put 'x-service 'plot-string 7)
  25.   (put 'x-service 'unplot-string 8)
  26.  
  27.   (defun xgap (win) (prin " " win))
  28.  
  29.   (defun openwin ()
  30.     (popen "xserver" 'output))
  31.  
  32.   (defun closewin (win)
  33.     (close win))
  34.  
  35.   (defun xterpri (win) (newline win))
  36.  
  37.   (defun send-code (win service)
  38.     (prin (get 'x-service service) win)
  39.     (flush win)
  40.     (xgap win))
  41.  
  42.   ;; plot pixmap at x y on window
  43.   (defun plot (win pm x y)
  44.     (open-semaphore lock)
  45.     (send-code win 'plot)
  46.     (prin pm win) (xgap win)
  47.     (prin x win) (xgap win)
  48.     (print y win)
  49.     (flush win)
  50.     (close-semaphore lock))
  51.  
  52.   ;; unplot pixmap at x y on window
  53.   (defun unplot (win pm x y)
  54.     (open-semaphore lock)
  55.     (send-code win 'unplot)
  56.     (prin pm win) (xgap win)
  57.     (prin x win) (xgap win)
  58.     (print y win)
  59.     (flush win)
  60.     (close-semaphore lock))
  61.  
  62.   ;; read a new pixmap
  63.   (defun read-pixmap (win name)
  64.     (open-semaphore lock)
  65.     (send-code win 'read-pixmap)
  66.     (print name win)     ;; without quotes
  67.     (xterpri win)
  68.     (flush win)
  69.     (close-semaphore lock))
  70.  
  71.   ;; clear the window
  72.   (defun clearwin (win)
  73.     (open-semaphore lock)
  74.     (send-code win 'clearwin)
  75.     (xterpri win)
  76.     (flush win)
  77.     (close-semaphore lock))
  78.  
  79.   ;; redraw the window
  80.   (defun redraw (win)
  81.     (open-semaphore lock)
  82.     (send-code win 'redraw)
  83.     (xterpri win)
  84.     (flush win)
  85.     (close-semaphore lock))
  86.  
  87.   ;; get the xserver to manage an object with pixmap pm
  88.   ;; the server remembers the last position and unplots it for you
  89.   ;; when you use move
  90.   (defun manage (win pm)
  91.     (open-semaphore lock)
  92.     (send-code win 'manage)
  93.     (print pm win)
  94.     (flush win)
  95.     (close-semaphore lock))
  96.  
  97.   ;; move a managed object
  98.   (defun move (win obj x y)
  99.     (open-semaphore lock)
  100.     (send-code win 'move)
  101.     (prin obj win) (xgap win)
  102.     (prin x win) (xgap win)
  103.     (print y win)
  104.     (flush win)
  105.     (close-semaphore lock))
  106.  
  107.   ;; plot a string
  108.   (defun plot-string (win x y str)
  109.     (open-semaphore lock)
  110.     (send-code win 'plot-string)
  111.     (prin x win) (xgap win)
  112.     (print y win) (xgap win)
  113.     (print str win) 
  114.     (flush win)
  115.     (close-semaphore lock))
  116.  
  117.   ;; unplot it
  118.   (defun unplot-string (win x y str)
  119.     (open-semaphore lock)
  120.     (send-code win 'unplot-string)
  121.     (prin x win) (xgap win)
  122.     (prin y win) (xgap win)
  123.     (print str win)
  124.     (flush win)
  125.     (close-semaphore lock))
  126.  
  127.   (export plot unplot read-pixmap clearwin redraw manage move
  128.       plot-string unplot-string)
  129.  
  130.  
  131. ;;  (plot-string X-stream "EuLisp FEEL" 210 10)
  132.  
  133. )
  134.